package ua.mk.chdu.rtem.diploma.core.agents.perfomancereport.behaviours;

import jade.core.behaviours.CyclicBehaviour;
import jade.core.behaviours.OneShotBehaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import ua.mk.chdu.rtem.diploma.core.agents.perfomancereport.PerformanceReportGeneratorAgent;
import ua.mk.chdu.rtem.diploma.core.model.enums.MessageTypes;
import ua.mk.chdu.rtem.diploma.core.model.vo.PerformanceReportVO;
import ua.mk.chdu.rtem.diploma.core.utils.PerformanceUtil;

import java.io.IOException;

public class GeneratePerformanceReportBehaviour extends CyclicBehaviour {
    private PerformanceReportGeneratorAgent agent;
    private MessageTemplate template = MessageTemplate.MatchAll();//MatchReplyWith(MessageTypes.GET_PERFORMANCE_REPORT.getValue());

    public GeneratePerformanceReportBehaviour(PerformanceReportGeneratorAgent agent) {
        super(agent);
        this.agent = agent;
    }

    @Override
    public void action() {
        //Retrieving request for performance report generation
        ACLMessage performanceRequest = agent.blockingReceive();
        System.out.println("RECEIVED REQUEST FOR PERFORMANCE REPORT GENERATION");

        //Building performance report
        PerformanceReportVO report = PerformanceUtil.generatePerformanceReport();

        //Creating response message
        ACLMessage performanceResult = performanceRequest.createReply();
        System.out.println("SENDING PERFORMANCE REPORT");
        System.out.println("IN REPLY TO=" + performanceResult.getInReplyTo());
        try {
            performanceResult.setContentObject(report);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //Sending response
        agent.send(performanceResult);
    }


}
